<script setup lang="ts">
import { reactive, ref } from 'vue';
import { useFormActions } from '@/composables/useFormActions';
import FormTemplate from '@/components/jg/FormTemplate.vue';

const formData = reactive({ a: 0, b: 0 });
const result = ref<number | null>(null);
const { calculate, generateReport } = useFormActions('businessA');

function handleCalculate() {
  calculate(formData).then(res => {
    if (res && res.data) {
      result.value = res.data.result;
    } else {
      // 处理接口失败或未返回 data 的逻辑
      console.error('计算接口未返回数据');
    }
  });
}
function handleReport() {
  generateReport(formData);
}
</script>

<template>
  <div>
    <FormTemplate title="双扇防护门计算" @calculate="handleCalculate" @report="handleReport">
      <NForm :model="formData">
        <NFormItem label="字段A"><NInputNumber v-model:value="formData.a" /></NFormItem>
        <NFormItem label="字段B"><NInputNumber v-model:value="formData.b" /></NFormItem>
      </NForm>
    </FormTemplate>
    <div v-if="result">计算结果：{{ result }}</div>
  </div>
</template>
